// pages/andon/analyse_line/analyse_line.js
const behavior = getApp().require("behaviors/requests.js")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [behavior],
  data: {
    location: "",
    show: false,
    currentPage: 1,
    totalPage: 1,
    tableTotal: 0,
    dataList: []
  },

  pageUp() {
    let now_page = this.data.currentPage
    if (now_page != 1) {
      now_page = now_page - 1
      this.setData({
        currentPage: now_page,
      })
      this.getDataList()
    }


  },
  pageDown() {
    let now_page = this.data.currentPage
    if (now_page < this.data.totalPage) {
      now_page = now_page + 1
      this.setData({
        currentPage: now_page
      })
      this.getDataList()
    }
  },

  getDataList() {
    var that = this
    this.get('https://logisticsengineering.gree.com/andon_system/get_line_info', {
      location: this.data.location,
      current: this.data.currentPage
    }).then((res) => {
      console.log(res.data)
      const data = res.data
      that.setData({
        dataList: data.table_data,
        tableTotal: data.table_total,
        totalPage: Math.ceil((data.table_total) / 10)
      });
    })
  },

  jumpTo(event) {
    const data = event.currentTarget.dataset["inner_data"]
    console.log("data", data)
    const inner_data = encodeURIComponent(JSON.stringify(data));
    wx.navigateTo({
      url: '/pages/andon/analyse_line_detail/analyse_line_detail?inner_data=' + inner_data,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      location: options.location
    });
    this.getDataList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})